package com.softplus.carrefour.hd.bltier.entity;

import com.softplus.carrefour.InfrastructureException;
import com.softplus.carrefour.hd.bltier.db.HibernateUtil;

import java.io.Serializable;

import java.util.Date;
import java.util.Set;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.expression.Expression;

import org.apache.commons.lang.builder.ToStringBuilder;


/** @author Hibernate CodeGenerator */
public class Country implements Serializable {

    /** identifier field */
    private String countryId;

    /** nullable persistent field */
    private String countryName;


    /** nullable persistent field */
    private String active;


    /** persistent field */
    private Set userAccounts;

    /** persistent field */

    /** full constructor */
    public Country(String countryId, String countryName, String localCurrency, 
                   Integer avgDayPerMonth, String active, String location, 
                   Integer noOfMd, Integer noOfStore, String credBy, 
                   Date credDate, String updBy, Date updDate, Set userAccounts, 
                   Set countryProjects, Set countryExchanges, Set costs, 
                   Set mdStores, Set holidays, Set documentContainers) {
        this.countryId = countryId;
        this.countryName = countryName;
        this.userAccounts = userAccounts;
    }

    /** default constructor */
    public Country() {
    }

    /** minimal constructor */
    public Country(String countryId, Set userAccounts, Set countryProjects, 
                   Set countryExchanges, Set costs, Set mdStores, Set holidays, 
                   Set documentContainers) {
        this.countryId = countryId;
        this.userAccounts = userAccounts;
    }

    public String getCountryId() {
        return this.countryId;
    }

    public void setCountryId(String countryId) {
        this.countryId = countryId;
    }

    public String getCountryName() {
        return this.countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }


    public String getActive() {
        return active;
    }

    public void setActive(String active) {
        this.active = active;
    }

    public Set getUserAccounts() {
        return this.userAccounts;
    }

    public void setUserAccounts(Set userAccounts) {
        this.userAccounts = userAccounts;
    }


    public String toString() {
        return new ToStringBuilder(this).append("countryId", 
                                                getCountryId()).toString();
    }

    public static Country getCountry(String countryId) {
        try {
            return (Country)HibernateUtil.getSession().createCriteria(Country.class).add(Expression.eq("countryId", 
                                                                                                       countryId)).uniqueResult();
        } catch (InfrastructureException ife) {
            return null;
        } catch (HibernateException hbe) {
            return null;
        }
    }

}
